package client;

import java.net.InetSocketAddress;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoConnector;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
import org.apache.mina.transport.socket.nio.SocketConnector;

import codec.LHCodecFactory;

public class LHClient {

	private static final int PORT = 9123;
	
	public LHClient() {
		ByteBuffer.setUseDirectBuffers(false);
		ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
		IoConnector socket = new SocketConnector();
		SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
        cfg.getFilterChain().addLast( "codec", new ProtocolCodecFilter(new LHCodecFactory(true)));
		ConnectFuture connector = socket.connect (new InetSocketAddress(PORT),new ClientHandler(),cfg);
		connector.join(3000);
		try{
			IoSession session = connector.getSession();
			
			
			session.write("appTeste.jar");
		//	session.close();
		}
		
		catch (RuntimeException e ){
			e.printStackTrace();
		}
	
		
		
		
	}



		
	
	public static void main (String args[]){
		new LHClient();
	}
	
}
